package com.phoenix.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 针对限流
 */
@RestController
@RequestMapping("/pilot")
@Slf4j
public class PilotController {

    @SentinelResource(value = "pilot_list",blockHandler = "blockHander")
    @GetMapping("/getList")
    public String getList(){
        return "success";
    }

    /**
     * 这个参数 异常类型如果不对 就不会走该方法
     * @param e
     * @return
     */
    public String blockHander(BlockException e){
        log.warn("触发限流",e);
        return "服务器繁忙，请稍后再试";
    }
}
